package com.springboot.frame.oauth.server.security.user;

import com.springboot.frame.oauth.server.vo.SysUserRoleResouceVo;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @author liheng
 * @ClassName DinePeopleDetails
 * @Description
 * @date 2020-08-20 20:36
 */
public class SysUserDetails extends SysUserRoleResouceVo implements UserDetails, Serializable {
    @Setter
    private Boolean accountNonExpired = true;
    @Setter
    private Boolean accountNonLocked = true;
    @Setter
    private Boolean credentialsNonExpired = true;
    @Setter
    private Boolean enabled = true;


    /**
     * 暂不做权限校验
     *
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
//        List<SysRole> userRoles = this.getRoles();
//        if (userRoles != null) {
//            for (SysRole role : userRoles) {
//                // Security 内部 需要使用ROLE_前缀来校验
//                SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_" + role.getRolename());
//                authorities.add(authority);
//            }
//        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return super.getPassword();
    }

    @Override
    public String getUsername() {
        return super.getAccount();
    }


    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

}
